package com.zy.nft_system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zy.nft_system.domain.Account;
import com.zy.nft_system.domain.Result;
import com.zy.nft_system.domain.dto.AccountDto;
import com.zy.nft_system.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 这是那头猪？
 * @version 1.0
 * @description: TODO
 * @date 2022/12/5 9:19
 */
@RequestMapping("/account")
@Slf4j
@RestController
public class AccountController {
    @Autowired
    AccountService accountService;

    @GetMapping("/userAccountList")
    public Result userAccountList(){
        log.info("正在查询账户信息");
        return accountService.userAccountList();
    }
    @GetMapping("/userAccountListLike")
    public Result userAccountListLike(String name){
        log.info("正在模糊查询账户信息");
        return accountService.userAccountListList(name);
    }

    @PutMapping("/updataAccount")
    public Result updataAccount(@RequestBody AccountDto accountDto){
        log.info("正在修改查询账户金额信息");
        return accountService.updataAccount(accountDto.getId(), accountDto.getOverage());
    }

    @GetMapping("/queryOverageById")
    public Result queryOverageById(Integer uid){
        log.info("正在查询账户金额");
        List<Account> uid1 = accountService.list(new QueryWrapper<Account>().eq("uid", uid));
        if(uid1.isEmpty()){
            log.info("查询失败，未找到账户");
            return Result.error("查询失败，未找到账户");
        }
        log.info("查询成功");
        return Result.success("查询成功", uid1);
    }
}
